Enabler for rust log to be used in S-CORE#6
Enabler for rust log to be used in S-CORE#6pawelrutkaq wants to merge 4 commits intoeclipse-score:mainfrom
Conversation
b4f3e69 to
c537c0a
Compare
Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
Import from log crate 3aa1359e926a39f841791207d6e57e00da3e68e2 at https://github.com/rust-lang/log Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
c537c0a to
f98cdb1
Compare
f98cdb1 to
d718849
Compare
Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
d718849 to
3b3dd62
Compare
darkwisebear
left a comment
There was a problem hiding this comment.
General comment: This looks like a copy & paste from the original log crate. Why not just use that one or re-use / re-export parts? Are there any changes to the crate? If yes, can you please point them out? We can then see how we can integrate those without running into a maintenance nightmare.
src/mw_log_subscriber/src/lib.rs
Outdated
| } | ||
|
|
||
| /// Sets the context for currently build logger. | ||
| pub fn context(mut self, context: &str) -> Self { |
There was a problem hiding this comment.
Should be called with_context imo.
src/mw_log_subscriber/src/lib.rs
Outdated
| } | ||
|
|
||
| /// Returns a slice to filled part of buffer. This is not null-terminated. | ||
| fn as_c_str(&self) -> &[c_char] { |
There was a problem hiding this comment.
This might be a misnomer: Since it is not null-terminated, it's also not a C string.
|
|
||
| /// Returns a slice to filled part of buffer. This is not null-terminated. | ||
| fn as_c_str(&self) -> &[c_char] { | ||
| unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast::<c_char>(), self.len()) } |
There was a problem hiding this comment.
You should add a SAFETY comment that explains why this is actually safe.
| } | ||
|
|
||
| const fn is_utf8_char_boundary(i: u8) -> bool { | ||
| // This is bit magic equivalent to: b < 128 || b >= 192 |
There was a problem hiding this comment.
I know that this is a copy from the standard lib, but why doing magic if you could just write it like that? The Rust safe coding guidelines will prohibit such casts anyway, so I suggest to turn your comment into code :)
There was a problem hiding this comment.
I think it's just 2 compares versus one optimization. Not sure what Rust safe coding has to do here.
There was a problem hiding this comment.
I assume that at some point this library will be used in a safe process. It then needs to comply to the Rust safety guidelines that are being developed. This construct would not be allowed, so sooner or later this has to either be suppressed or be changed.
| } | ||
| } | ||
|
|
||
| struct BufWriter<const BUF_SIZE: usize> { |
There was a problem hiding this comment.
Please document what the purpose of this thing is. From reverse engineering the code, it seems you manage a preallocated buffer by copying as many UTF8 bates into the buffer as possibly can fit.
src/mw_log_subscriber/src/lib.rs
Outdated
| log_fn: fn(&mut BufWriter<MSG_SIZE>, &Record), | ||
| } | ||
|
|
||
| // SAFETY: The underlying C++ logger is assumed to be safe to change thread |
There was a problem hiding this comment.
"assumed" is a bit weak. Turn it into "known" if you know.
| #include "score/mw/log/logger.h" | ||
| #include "score/mw/log/log_level.h" | ||
|
|
||
| namespace score |
| extern "C" | ||
| { | ||
|
|
||
| Logger *mw_log_create_logger(const char *context) |
There was a problem hiding this comment.
No as Loggers are maintaned by logging.
There was a problem hiding this comment.
Then it should probably be called "mw_log_get_logger" so that it's clear that this is a non-owning pointer. Maybe you should also elaborate on the lifetime of the pointer.
|
|
||
| void mw_log_fatal_logger(const Logger *logger, const char *message, uint32_t size) | ||
| { | ||
| logger->LogFatal() << LogString{message, size}; |
There was a problem hiding this comment.
Just use std::string_view, should be the cleaner way.
There was a problem hiding this comment.
I think this is better as logging says that This class only supports the logging of the following basic data types:: ..., std::string_view (via implicit conversion to mw::log::LogString) so we skip one hop now.
|
|
||
| extern "C" { | ||
|
|
||
| pub(crate) fn mw_log_create_logger(context: *const c_char) -> *const Logger; |
There was a problem hiding this comment.
Nit: The returned value is of type *mut Logger in C++.
SInce the idea was to break dep to |
Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
It seems that S-CORE wants to deviate from the canonical Rust way of logging, which is the |
The |
|
@arsibo @rmaddikery @hoppe-and-dreams my understanding
|
OSSC == Open source scan converter..? Before deciding to fork the crate (which is effectively what's happening here) we should clarify with upstream whether the necessary changes would be accepted here. Therefore we should collect the known additional parts and open issues upstream. So my questions would be
|
Closes #5